import * as moment from "moment";

declare global {
  interface Array<T> {
    DateFormatMap(...args:any): Array<T>
  }
}
export class customArray extends Array {
    constructor(){
        super()
    }
    // 格式化日期map
    DateFormatMap(...args) {
        // eslint-disable-next-line @typescript-eslint/no-this-alias
        const array = this;
        const result = [];
        for(const value of array) {
          if (value != null && typeof value == 'object') {
            Object.keys(value).forEach((key) => {
                // **_time 字段的都将以为是时间类型
              const flag = key.split('_').pop()
              if(flag === 'time') {
                if(Number(value[key]) > 0 && moment(Number(value[key])).isValid()) {
                  value[key] = moment(Number(value[key])).format(args[1] || 'YYYY-MM-DD HH:mm:ss')
                } else if(moment(value[key]).isValid()) {
                  value[key] = moment(value[key]).format(args[1] || 'YYYY-MM-DD HH:mm:ss')
                }
              }
            })
          }
          result.push(args[0](value))
        }
        return result
    };
}
